package com.pi.pro.xcmg.am.was.web.cust.controller;

import com.pi.common.utils.StringUtils;
import com.pi.framework.core.controller.BaseCrudController;
import com.pi.framework.core.service.ICrudService;
import com.pi.framework.core.util.SecurityUtils;
import com.pi.wms.entity.TwaInventoryLotnum;
import com.pi.wms.entity.VwaInventoryLotnumStorageage;
import com.pi.wms.repository.LotnumStorageageRepository;
import com.pi.wms.service.InventoryLotnumService;
import com.pi.wms.service.LotnumStorageageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.datatables.mapping.DataTablesInput;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Controller
@RequestMapping("/inventory/invlot/ca")
public class CustApplyInventoryLotnumController extends BaseCrudController<VwaInventoryLotnumStorageage, Long> {

	@Autowired
	private LotnumStorageageService service;
	
	
	@Override
	protected ICrudService<VwaInventoryLotnumStorageage, Long> getCrudService() {
	    return service;
	}

	@Override
	protected String getPrefix() {
		return "invlot";
	}

	@Override
	protected void prepareDatatableConditions(Map<String, Object> query, DataTablesInput input) {
		Long userId = SecurityUtils.getLoginUserId();
		query.put("userId", userId.toString());
		super.prepareDatatableConditions(query, input);
	}

	protected String redirect(String relativeUrl) {
		if(!StringUtils.isNullOrBlank(relativeUrl) && !relativeUrl.startsWith("/")) {
			relativeUrl = "/" + relativeUrl;
		}
		return "redirect:" + this.referUrl() + relativeUrl;
	}

	private String referUrl(){
		return "/inventory/invlot/";
	}
}
